<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../../../static/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../static/css/admin.css" media="all">
    <style>
        .layui-table{
            text-align: center!important;
        }
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" style="border-radius: 0;border-top: 4px solid #d2d2d2;">
            <div class="layui-form-item">

                <div class="layui-inline" style="margin-left: -60px">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="name" autocomplete="off" class="layui-input" style="width: 100px!important;">
                    </div>
                </div>
                <div class="layui-inline" style="margin-left: -140px">
                    <label class="layui-form-label">应聘职位</label>
                    <div class="layui-input-inline" style="width: 150px!important;">
                        <select name="job_name" id="job_name">
                            <option value=""></option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline" style="margin-left: -50px">
                    <label class="layui-form-label">工作经验</label>
                    <div class="layui-input-inline" style="width: 100px!important;">
                        <select name="experience" >
                            <option value=""></option>
                            <option value="1">1年</option>
                            <option value="2">2年</option>
                            <option value="3">3年及以上</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline" style="margin-left: -50px">
                    <label class="layui-form-label">简历状态</label>
                    <div class="layui-input-inline" style="width: 100px!important;">
                        <select name="status" >
                            <option value=""></option>
                            <option value="0">存档</option>
                            <option value="1">推荐面试</option>
                            <option value="2">推荐二面</option>
                            <option value="3">推荐三面</option>
                            <option value="4">建议录用</option>
                            <option value="5">录用</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-inline" style="margin-top: 10px; margin-left: -50px">
                    <label class="layui-form-label">登记时间</label>
                    <div class="layui-input-inline">
                        <input type="text" name="reg_time"  autocomplete="off" class="layui-input" id="test1" placeholder="yyyy-MM-dd" readonly>
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-emp-front-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <div style="padding-bottom: 10px;">
                <button class="layui-btn layuiadmin-btn-useradmin" data-type="add">简历登记</button>
            </div>

            <table id="LAY-user-manage" lay-filter="LAY-user-manage" style="text-align: center!important;"></table>

            <script type="text/html" id="table-useradmin-webuser">
                {{#  if(d.status == 0){ }}
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail"><i class="layui-icon layui-icon-edit"></i>明细</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
                {{#  } else if(d.status == 1 || d.status == 2 || d.status == 3) {}}
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail"><i class="layui-icon layui-icon-edit"></i>明细</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
                {{#  } else if(d.status > 3) {}}
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail"><i class="layui-icon layui-icon-edit"></i>明细</a>
                {{#  } }}
            </script>

            <!--性别判断-->
            <script type="text/html" id="sexTpl">
                {{#  if(d.sex == 0){ }}
                男
                {{#  } else if(d.sex == 1) {}}
                女
                {{#  } }}
            </script>
            <script type="text/html" id="statusTpl">
                {{#  if(d.status == 0){ }}
                存档
                {{#  } else if(d.status == 1) {}}
                推荐面试
                {{#  } else if(d.status == 2) {}}
                推荐二面
                {{#  } else if(d.status == 3) {}}
                推荐三面
                {{#  } else if(d.status == 4) {}}
                建议录用
                {{#  } else if(d.status == 5) {}}
                录用
                {{#  } else if(d.status == 6) {}}
                删除
                {{#  } }}
            </script>

            <!--  日期格式化处理 -->
            <script type="text/html" id="reg_timeTpl">
                {{formatDate(d.reg_time)}}
            </script>

        </div>
    </div>
</div>

<!--<script src="js/jquery-2.0.3.min.js"></script>-->
<script src="../../../static/layui/layui.js"></script>

<!--日期格式化函数-->
<script type="text/javascript">
    function formatDate(str) {
        if(str != null){
            var now = new Date(str);
            var year = now.getFullYear();  //取得4位数的年份
            var month = now.getMonth() + 1;  //取得日期中的月份，其中0表示1月，11表示12月
            var date = now.getDate();      //返回日期月份中的天数（1到31）
            return year + "-" + month + "-" + date;
        }
        return "";
    }
</script>
<script type="text/javascript">

    layui.use(['layer','table','form','element','util','laydate'], function(){
        var $ = layui.$
            ,form = layui.form
            ,layer = layui.layer
            ,table = layui.table
            ,element = layui.element
            ,util = layui.util
            ,laydate = layui.laydate;

        //获取登录信息
        var userInfo = sessionStorage.getItem("user");
        var user = JSON.parse(userInfo);

        //获取职位名称
        $.ajax({
            url:"/recruit/getJobName",
            type:"post",
            data:{},
            dataType:"json",
            success:function (res){
                if(res.code == 0){
                    let selectElement=document.getElementById("job_name");

                    for(let i=0;i<res.data.length;i++){
                        let optionElement = document.createElement("option");
                        optionElement.text=res.data[i].job_name;
                        optionElement.value=res.data[i].job_name;
                        selectElement.add(optionElement);
                        //console.log(selectElement);
                    }
                    form.render();
                }
            },error:function (res){

            }
        })


        //加载table
        table.render({
            elem: '#LAY-user-manage'
            ,url:'/recruit/resume/findAllResumes' //后端接口
            ,title: '雇员数据表'
            ,cellMinWidth: 100 //全局定义常规单元格的最小宽度
            ,cols: [[
                {type: 'checkbox', fixed: 'left',align:'center'}
                ,{field:'resume_id',title:'简历编号',hide:true}
                ,{field:'identity',title:'身份证号',hide:true}
                ,{field:'recruit_type',title:'招聘类型',hide:true}
                ,{field:'location',title:'户口所在地',hide:true}
                ,{field:'address',title:'住址',hide:true}
                ,{field:'phone',title:'电话号码',hide:true}
                ,{field:'email',title:'邮箱',hide:true}
                ,{field:'politic_outlook',title:'政治面貌',hide:true}
                ,{field:'salary',title:'薪资要求',hide:true}
                ,{field:'is_work',title:'是否在职',hide:true}
                ,{field:'is_graduate',title:'是否应届生',hide:true}
                ,{field:'resume',title:'个人履历',hide:true}
                ,{field:'resume_url',title:'简历url',hide:true}
                ,{field:'is_recom',title:'是否推荐面试',hide:true}
                ,{field:'recommender',title:'推荐人',hide:true}
                ,{field:'recom_time',title:'推荐时间',hide:true}
                ,{field:'recom_advice', title:'推荐面试意见',hide:true}
                ,{field:'job_id', title:'职位编号',hide:true}
                ,{field:'name',title:'姓名',align:'center'}
                ,{field:'sex', title:'性别',align:'center',templet:'#sexTpl'}
                ,{field:'graduate_school', title:'毕业院校',align:'center'}
                ,{field:'degree', title:'学历',align:'center'}
                ,{field:'major', title:'专业',align:'center',width: 150}
                ,{field:'job_name', title:'应聘职位',align:'center'}
                ,{field:'experience', title:'工作经验',align:'center',width: 150}
                ,{field:'reg_ime', title:'登记日期',align:'center',templet:'#reg_timeTpl'}
                ,{field:'status', title:'简历状态',align:'center',templet:'#statusTpl'}
                ,{fixed: 'right', title:'操作', toolbar: '#table-useradmin-webuser',width:280,align:'center'}
            ]]
            ,page: {
                curr: 1 //设定初始在第 5 页
                ,limit: 5 //设定初始每页显示 5 条
            },
            limits:[5,10,15,20]
        });

        //监听行工具事件
        table.on('tool(LAY-user-manage)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    $.ajax({
                        url:"/recruit/resume/delResume", //请求后端接口地址
                        type:"post", //请求方式get | post
                        data:{resume_id:data.resume_id}, //提交json字符串对象参数
                        dataType:"json", //后端返回参数类型
                        success:function (res){ //请求成功后回调函数res = JSONObject.toJSONString(resultMap)
                            if(res.code == 0){//成功
                                layer.msg(res.msg);//弹出提示
                                table.reload('LAY-user-manage'); //数据刷新
                                layer.close(index); //关闭弹层
                            }
                            if(res.code == -1){//系统出问题
                                layer.msg(res.msg,{icon: 5});//弹出提示
                            }
                        }
                    })
                });
            }
            else if(obj.event === 'detail'){
                layer.open({
                    type: 2
                    ,title: '简历明细'
                    ,skin: 'layui-layer-molv'
                    ,content: 'detailResume.html'
                    ,maxmin: true
                    ,area: ['1100px', '600px']
                    ,success: function (layero,index){
                        var body = layer.getChildFrame("body",index);
                        var contentWindow = layero.find('iframe')[0].contentWindow;//得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                        body.find("input[name=job_name]").val(data.job_name).prop("readonly",true);
                        body.find("input[name=job_id]").val(data.job_id).prop("readonly",true);
                        body.find("input[name=job_type]").val(data.job_type).prop("readonly",true);
                        body.find("input[name=name]").val(data.name).prop("readonly",true);
                        body.find("input[name=email]").val(data.email).prop("readonly",true);
                        body.find("input[name=phone]").val(data.phone).prop("readonly",true);
                        body.find("input[name=location]").val(data.location).prop("readonly",true);
                        body.find("input[name=address]").val(data.address).prop("readonly",true);
                        body.find("input[name=identity]").val(data.identity).prop("readonly",true);
                        body.find("input[name=politic_outlook]").val(data.politic_outlook).prop("readonly",true);
                        body.find("input[name=graduate_school]").val(data.graduate_school).prop("readonly",true);
                        body.find("input[name=major]").val(data.major).prop("readonly",true);
                        body.find("input[name=degree]").val(data.degree).prop("readonly",true);
                        body.find("input[name=experience]").val(data.experience).prop("readonly",true);
                        body.find("input[name=salary]").val(data.salary).prop("readonly",true);
                        body.find("input[name=recommender]").val(data.recommender).prop("readonly",true);
                        body.find("textarea[name=resumes]").val(data.resumes).prop("readonly",true);
                        body.find("textarea[name=recom_advice]").val(data.recom_advice).prop("readonly",true);

                        var selectedRole1 = data.recruit_type;
                        var roleSelect1 = body.find("select[name=recruit_type]").prop("readonly",true);
                        roleSelect1.val(selectedRole1);

                        var selectedRole2 = data.sex;
                        var roleSelect2 = body.find("select[name=sex]").prop("readonly",true);
                        roleSelect2.val(selectedRole2);

                        var selectedRole3 = data.degree;
                        var roleSelect3 = body.find("select[name=degree]").prop("readonly",true);
                        roleSelect3.val(selectedRole3);

                        var selectedRole4 = data.is_work;
                        var roleSelect4 = body.find("select[name=is_work]").prop("readonly",true);
                        roleSelect4.val(selectedRole4);

                        var selectedRole5 = data.is_graduate;
                        var roleSelect5 = body.find("select[name=is_graduate]").prop("readonly",true);
                        roleSelect5.val(selectedRole5);

                        var selectedRole6 = data.is_recom;
                        var roleSelect6 = body.find("select[name=is_recom]").prop("readonly",true);
                        roleSelect6.val(selectedRole6);
                        contentWindow.layui.form.render();

                        console.log(data.reg_time)
                        var now = new Date(data.reg_time);
                        var year = now.getFullYear();  //取得4位数的年份
                        var month = now.getMonth() + 1;  //取得日期中的月份，其中0表示1月，11表示12月
                        var date = now.getDate();      //返回日期月份中的天数（1到31）
                        var reg_time = year + "-" + month + "-" + date;
                        body.find("input[name=reg_time]").val(reg_time).prop("readonly",true);

                        var now2 = new Date(data.recom_time);
                        var year2 = now2.getFullYear();  //取得4位数的年份
                        var month2 = now2.getMonth() + 1;  //取得日期中的月份，其中0表示1月，11表示12月
                        var date2 = now2.getDate();      //返回日期月份中的天数（1到31）
                        var recom_time = year2 + "-" + month2 + "-" + date2;
                        body.find("input[name=recom_time]").val(recom_time).prop("readonly",true);


                    }
                    ,btn: ['返回']
                });

            }
            else if(obj.event === 'edit'){
                layer.open({
                    type: 2
                    ,title: '编辑简历信息'
                    ,skin: 'layui-layer-molv'
                    ,content: 'editResume.html'
                    ,maxmin: true
                    ,area: ['1100px', '600px']
                    ,success: function (layero,index){
                        var body = layer.getChildFrame("body",index);
                        var contentWindow = layero.find('iframe')[0].contentWindow;//得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                        body.find("input[name=resume_id]").val(data.resume_id);
                        body.find("input[name=job_name]").val(data.job_name);
                        body.find("input[name=job_id]").val(data.job_id);
                        body.find("input[name=job_type]").val(data.job_type);
                        body.find("input[name=name]").val(data.name);
                        body.find("input[name=email]").val(data.email);
                        body.find("input[name=phone]").val(data.phone);
                        body.find("input[name=location]").val(data.location);
                        body.find("input[name=address]").val(data.address);
                        body.find("input[name=identity]").val(data.identity);
                        body.find("input[name=graduate_school]").val(data.graduate_school);
                        body.find("input[name=politic_outlook]").val(data.politic_outlook).prop("readonly",true);
                        body.find("input[name=degree]").val(data.degree);
                        body.find("input[name=experience]").val(data.experience);
                        body.find("input[name=major]").val(data.major);
                        body.find("input[name=salary]").val(data.salary);
                        body.find("input[name=recommender]").val(data.recommender);
                        body.find("textarea[name=resumes]").val(data.resumes);
                        body.find("textarea[name=recom_advice]").val(data.recom_advice);

                        var selectedRole1 = data.recruit_type;
                        var roleSelect1 = body.find("select[name=recruit_type]");
                        roleSelect1.val(selectedRole1);

                        var selectedRole2 = data.sex;
                        var roleSelect2 = body.find("select[name=sex]");
                        roleSelect2.val(selectedRole2);

                        var selectedRole3 = data.degree;
                        var roleSelect3 = body.find("select[name=degree]");
                        roleSelect3.val(selectedRole3);

                        var selectedRole4 = data.is_work;
                        var roleSelect4 = body.find("select[name=is_work]");
                        roleSelect4.val(selectedRole4);

                        var selectedRole5 = data.is_graduate;
                        var roleSelect5 = body.find("select[name=is_graduate]");
                        roleSelect5.val(selectedRole5);

                        var selectedRole6 = data.is_recom;
                        var roleSelect6 = body.find("select[name=is_recom]");
                        roleSelect6.val(selectedRole6);
                        contentWindow.layui.form.render();


                        var now = new Date(data.reg_time);
                        var year = now.getFullYear();  //取得4位数的年份
                        var month = now.getMonth() + 1;  //取得日期中的月份，其中0表示1月，11表示12月
                        var date = now.getDate();      //返回日期月份中的天数（1到31）
                        var reg_time = year + "-" + month + "-" + date;
                        body.find("input[name=reg_time]").val(reg_time);

                        var now2 = new Date(data.recom_time);
                        var year2 = now2.getFullYear();  //取得4位数的年份
                        var month2 = now2.getMonth() + 1;  //取得日期中的月份，其中0表示1月，11表示12月
                        var date2 = now2.getDate();      //返回日期月份中的天数（1到31）
                        var recom_time = year2 + "-" + month2 + "-" + date2;
                        body.find("input[name=recom_time]").val(recom_time);
                    }
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        var iframeWindow = window['layui-layer-iframe'+ index]
                            ,submitID = 'LAY-user-front-submit'
                            ,submit = layero.find('iframe').contents().find('#'+ submitID);
                        //console.log(submit)
                        //监听提交
                        iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
                            var field = data.field; //获取提交的字段
                            console.log(field)
                            $.ajax({
                                url:"/recruit/resume/editResume", //请求后端接口地址
                                type:"post", //请求方式get | post
                                data:JSON.stringify(field), //提交json字符串对象参数
                                contentType:"application/json;charset=utf-8", //发送信息至服务器时内容编码类型
                                dataType:"json", //后端返回参数类型
                                success:function (res){ //请求成功后回调函数res = JSONObject.toJSONString(resultMap)
                                    if(res.code == 0){//成功
                                        layer.msg(res.msg);//弹出提示
                                        table.reload('LAY-user-manage'); //数据刷新
                                        layer.close(index); //关闭弹层
                                    }
                                    if(res.code == -1){//系统出问题
                                        layer.msg(res.msg,{icon: 5});//弹出提示
                                    }
                                }
                            })
                        });
                        submit.trigger('click');
                    }
                });

            }
        });


        //监听搜索
        form.on('submit(LAY-emp-front-search)', function(data){
            var field = data.field;
            console.log(field)
            // 调用后端接口，传递参数
            table.reload('LAY-user-manage', {
                url:"/recruit/resume/searchResume", //后端搜索接口URL地址
                where: field
            });
        });

        //事件
        var active = {
            batchdel: function(){
                var checkStatus = table.checkStatus('LAY-user-manage')
                    ,checkData = checkStatus.data; //得到选中的数据

                if(checkData.length == 0){
                    return layer.msg('请选择数据');
                }

                // 程序走到这里，表示已经有选中要删除的数据了。
                layer.confirm('确定删除吗？',function (){
                    //真实删除，应该和后端结合 ajax
                    var empnos = new Array();
                    $.each(checkData,function (index,item){
                        // 向数组对象中添加元素
                        empnos.push(item.empno);
                    })
                    $.ajax({
                        url:"/emp/batchdel",
                        type:"post",
                        data:{empnos:empnos},
                        traditional:true,
                        dataType:"json",
                        success:function (res){
                            if(res.code == 0){//成功
                                layer.msg(res.msg);//弹出提示
                                table.reload('LAY-user-manage'); //数据刷新
                            }
                            if(res.code == -1){//系统出问题
                                layer.msg(res.msg,{icon: 5});//弹出提示
                            }
                        }
                    })
                })
            }
            ,add: function() {
                window.location.href = "addResume.html";
            }
        };

        $('.layui-btn.layuiadmin-btn-useradmin').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        /*时间选择*/
        laydate.render({
            elem: '#test1'
        });
    });
</script>
</body>
</html>